package appconfig

import (
	"fmt"
	"github.com/spf13/viper"
)

type Mysql struct {
	User     string
	Password string
	Host     string
	Port     int
	Database string
}
type Redis struct {
	Host     string
	Port     int
	Password string
	Database int
}
type AppConf struct {
	Mysql Mysql
	Redis Redis
}

var Conf AppConf

func Init() {
	var err error
	//设置配置文件路径
	viper.SetConfigFile("appconfig/dev.yaml")
	//读取配置
	err = viper.ReadInConfig()
	if err != nil {
		panic(err)
	}

	//配置映射到变量
	err = viper.Unmarshal(&Conf)
	if err != nil {
		panic(err)
	}
	fmt.Println("配置成功", Conf)
}
